package com.zgt.web.action;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDriven;
import com.zgt.model.Setting;
import com.zgt.service.SettingService;
import com.zgt.web.AbstractAction;

@Controller("settingAction")
@Scope("prototype")
public class SettingAction extends AbstractAction implements
		ModelDriven<Setting> {
	
	private Map request;
	private Setting setting = new Setting();
	private SettingService settingService;
		
	public String add() {
		settingService.saveSetting(setting);
		request = (Map) ActionContext.getContext().get("request");
		request.put("url", "setting_list.action");
		return SUCCESS;
	}
	
	public Setting getModel() {
		return setting;
	}
	
	public SettingService getSettingService() {
		return settingService;
	}

	public String list(){
		setting = settingService.listSetting(1);
		request = (Map) ActionContext.getContext().get("request");
		request.put("setting", setting);
		return INPUT;
	}


	@Resource(name="settingService")
	public void setSettingService(SettingService settingService) {
		this.settingService = settingService;
	}

	public void validateAdd() {
		// TODO Auto-generated method stub
		System.out.println("validate");
		if("".equals(setting.getEmail()) || null==setting.getEmail()){
			this.addFieldError("e_msg", "email不能为空");
		}
	}

}
